package main

import (
	"fmt"
	"reflect"
)

func call1(i1 int, i2 int, str string) string {
	fmt.Printf("call1, %v, %v, %v\n", i1, i2, str)
	return "ok"
}

func call2(i1 int, i2 int) {
	fmt.Printf("call2, %v, %v\n", i1, i2)
}

func bridge(call interface{}, args ...interface{}) []interface{} {
	var (
		method    reflect.Value
		arguments []reflect.Value
		n         int
	)

	n = len(args)
	arguments = make([]reflect.Value, n)

	for i := 0; i < n; i++ {
		arguments[i] = reflect.ValueOf(args[i])
	}

	method = reflect.ValueOf(call)
	result := method.Call(arguments)

	var results []interface{}
	results = make([]interface{}, len(result))
	for i := 0; i < len(result); i++ {
		results[i] = result[i].Interface()
	}

	return results
}

func main() {

	r1 := bridge(call1, 1, 2, "1")
	fmt.Println(r1)

	r2 := bridge(call2, 1, 2)
	fmt.Println(r2)
}
